package com.hit.server.biz.controller;

import com.hit.common.core.util.R;
import com.hit.common.log.annotation.SysLog;
import com.hit.server.api.dto.SysRoleProjectSaveDTO;
import com.hit.server.api.service.SysRoleProjectService;
import com.hit.server.api.vo.SysProjectVO;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 角色项目表
 *
 * @author kehanjiang
 * @date 2025-04-10 08:45:17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysRoleProject")
@Tag(description = "sysRoleProject", name = "角色项目表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SysRoleProjectController {

    private final SysRoleProjectService sysRoleProjectService;


    /**
     * 通过roleId查询projectId集合
     *
     * @param roleId roleId
     * @return R
     */
    @Operation(summary = "通过roleId查询projectId集合", description = "通过roleId查询projectId集合")
    @GetMapping("/{roleId}")
    public R<List<Long>> getProjectsByRoleId(@PathVariable("roleId") Long roleId) {
        return R.ok(sysRoleProjectService.getProjectsByRoleId(roleId));
    }

    /**
     * 新增角色项目
     *
     * @param dto 角色项目表
     * @return R
     */
    @Operation(summary = "新增角色项目", description = "新增角色项目")
    @SysLog("新增角色项目")
    @PostMapping
    public R<Boolean> save(@RequestBody SysRoleProjectSaveDTO dto) {
        return R.ok(sysRoleProjectService.saveSysRoleProject(dto));
    }
}